/******************** 
	作用:佣金审核
	修改:白菜
	版本:V1.0
	时间:2015-07-28
********************/

$(function() {
	var tog = 0;//展开状态，1:已展开
	
	//点击"操作"按钮
	$("tbody[data-type=detailed] a").on("click", function() {
		var htmlTr = '';
		var id = $(this).closest("tr").attr("data-id");//获取当前数据id编号
		if(tog > 0){
			$('#detailed').remove();
			if(tog == id){
				tog = 0;
				return;
			}
		}
		
		//下面这段代码仅供前端页面测试，可删除
		data=[['1','2','3','4'],['22','23','33','44']];
		for(var i=0;i<data.length;i++){
			var item=data[i];
			htmlTr += '<tr><td class="center">'+item[2]+'</td><td class="center">XXX</td><td class="center">5%</td><td class="center">5</td><td class="center">20</td><td class="center">0</td><td class="center">未返佣</td></tr>';
			console.log(i+":"+item.a+","+item.b);
		}
		var htm = '<tbody id="detailed" style="display:none;"><tr><td colspan="8" style="padding-top: 0;"><table class="table table-bordered table-vertical-middle" style="width:80%;margin-left:10%;"><thead><tr><th class="center">分佣者ID</th><th class="center">昵称</th><th class="center">分佣比例</th><th class="center">现金</th><th class="center">积分</th><th class="center">红包</th><th class="center">状态</th></tr></thead> <tbody>'+htmlTr+'<tr><td class="center" colspan="8"><a class="btn btn-info btn-sm"  href="#" style="margin-right: 20px;">审核通过</a><a class="btn btn-info btn-sm" href="#" style="margin-left: 20px;">审核不通过</a></td></tr></tbody></table></td></tr></tbody>';
		$(this).parent().parent().parent().after(htm);
		$('#detailed').slideToggle();
		tog = id;
		//上面代码仅供测试
		//</tbody></table></td></tr></tbody><tbody>
		//ajax使用下面这段代码获取数据
		/*
		var options = {};
		var url = '';//程序路径
		var data = {id:id};
		var tip = '';
		Common.ajaxPost(options, null, url, data, tip, returnData, returnError);
		*/
		//获取数据成功
		function returnData(options, data, status) {
			data=[['1','2','3','4'],['1','2','3','4']];
			for(var i=0;i<data.length;i++){
				var item=data[i];
				htmlTr += '<tr><td class="center">'+item[2]+'</td><td class="center">XXX</td><td class="center">5%</td><td class="center">5</td><td class="center">20</td><td class="center">0</td><td class="center">未返佣</td></tr>';
				console.log(i+":"+item.a+","+item.b);
			}
			var htm = '<tbody id="detailed" style="display:none;"><tr><td colspan="8" style="padding-top: 0;"><table class="table table-bordered table-vertical-middle" style="width:80%;margin-left:10%;"><thead><tr><th class="center">分佣者ID</th><th class="center">昵称</th><th class="center">分佣比例</th><th class="center">现金</th><th class="center">积分</th><th class="center">红包</th><th class="center">状态</th></tr></thead> <tbody>'+htmlTr+'<tr><td class="center" colspan="8"><a class="btn btn-info btn-sm"  href="#" style="margin-right: 20px;">审核通过</a><a class="btn btn-info btn-sm" href="#" style="margin-left: 20px;">审核不通过</a></td></tr></tbody></table></td></tr></tbody>';
			$(this).parent().after(htm);
			tog = id;
		};
		//获取数据失败
		function returnError() {
			//alert("获取数据失败!");
		};
	});
});